package com.uduemc.biso.web.api.server.impl;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.uduemc.biso.core.extities.center.SysComponentType;
import com.uduemc.biso.core.feign.SysComponentTypeFeign;
import com.uduemc.biso.core.utils.RestResult;
import com.uduemc.biso.web.api.server.ComponentService;

@Service
public class ComponentServiceImpl implements ComponentService {

	@Autowired
	private SysComponentTypeFeign sysComponentTypeFeign;

	@Autowired
	private ObjectMapper objectMapper;

	@SuppressWarnings("unchecked")
	@Override
	public List<SysComponentType> findAll() {
		RestResult restResult = sysComponentTypeFeign.findAll();
		if (restResult == null || restResult.getCode() != 200 || restResult.getData() == null) {
			return null;
		}
		List<SysComponentType> data = null;
		try {
			data = (List<SysComponentType>) objectMapper.readValue(
					objectMapper.writeValueAsString(restResult.getData()), new TypeReference<List<SysComponentType>>() {
					});
		} catch (IOException e) {
			e.printStackTrace();
		}
		return data;
	}

}
